---
title: Daytona
description: Enable your Agents to run code in a remote, secure sandbox.
---

**Daytona** offers secure and elastic infrastructure for runnning your AI-generated code. At Agno, we integrate with it to enable your Agents and Teams to run code in your Daytona sandboxes.

## Prerequisites

The Daytona tools require the `daytona_sdk` Python package:

```shell
pip install daytona_sdk
```

You will also need a Daytona API key. You can get it from your [Daytona account](https://app.daytona.io/account):

```shell
export DAYTONA_API_KEY=your_api_key
```

## Example

The following example demonstrates how to create an agent that can run Python code in a Daytona sandbox:

```python cookbook/tools/daytona_tools.py
from agno.agent import Agent
from agno.models.anthropic import Claude
from agno.tools.daytona import DaytonaTools

daytona_tools = DaytonaTools()

# Setup an Agent focused on coding tasks, with access to the Daytona tools
agent = Agent(
    name="Coding Agent with Daytona tools",
    id="coding-agent",
    model=Claude(id="claude-sonnet-4-20250514"),
    tools=[daytona_tools],
    markdown=True,
        instructions=[
        "You are an expert at writing and validating Python code. You have access to a remote, secure Daytona sandbox.",
        "Your primary purpose is to:",
        "1. Write clear, efficient Python code based on user requests",
        "2. Execute and verify the code in the Daytona sandbox",
        "3. Share the complete code with the user, as this is the main use case",
        "4. Provide thorough explanations of how the code works",
        "You can use the run_python_code tool to run Python code in the Daytona sandbox.",
        "Guidelines:",
        "- ALWAYS share the complete code with the user, properly formatted in code blocks",
        "- Verify code functionality by executing it in the sandbox before sharing",
        "- Iterate and debug code as needed to ensure it works correctly",
        "- Use pandas, matplotlib, and other Python libraries for data analysis when appropriate",
        "- Create proper visualizations when requested and add them as image artifacts to show inline",
        "- Handle file uploads and downloads properly",
        "- Explain your approach and the code's functionality in detail",
        "- Format responses with both code and explanations for maximum clarity",
        "- Handle errors gracefully and explain any issues encountered",
    ],
)

# Example: Generate Fibonacci numbers
agent.print_response(
    "Write Python code to generate the first 10 Fibonacci numbers and calculate their sum and average"
)
```

## Toolkit Params

| Parameter             | Type             | Default               | Description                                                    |
| --------------------- | ---------------- | --------------------- | -------------------------------------------------------------- |
| `api_key`             | `str`            | `None`                | Daytona API key. If not provided, uses DAYTONA_API_KEY env var |
| `api_url`             | `str`            | `None`                | Daytona API URL. If not provided, uses DAYTONA_API_URL env var |
| `sandbox_id`          | `str`            | `None`                | Existing sandbox ID to connect to                              |
| `sandbox_language`    | `CodeLanguage`   | `CodeLanguage.PYTHON` | The programming language to run on the sandbox                 |
| `sandbox_target`      | `str`            | `None`                | The target configuration for sandbox creation                  |
| `sandbox_os`          | `str`            | `None`                | The operating system to run on the sandbox                     |
| `auto_stop_interval`  | `int`            | `60`                  | Stop sandbox after this many minutes of inactivity             |
| `sandbox_os_user`     | `str`            | `None`                | The user to run the sandbox as                                 |
| `sandbox_env_vars`    | `Dict[str, str]` | `None`                | Environment variables to set in the sandbox                    |
| `sandbox_labels`      | `Dict[str, str]` | `None`                | Labels to set on the sandbox                                   |
| `sandbox_public`      | `bool`           | `None`                | Whether the sandbox should be public                           |
| `organization_id`     | `str`            | `None`                | The organization ID to use for the sandbox                     |
| `timeout`             | `int`            | `300`                 | Timeout in seconds for communication with the sandbox          |
| `auto_create_sandbox` | `bool`           | `True`                | Whether to automatically create a sandbox if none exists       |
| `verify_ssl`          | `bool`           | `False`               | Whether to verify SSL certificates                             |
| `persistent`          | `bool`           | `True`                | Whether the sandbox should persist between requests            |
| `instructions`        | `str`            | `None`                | Custom instructions for using the Daytona tools                |
| `add_instructions`    | `bool`           | `False`               | Whether to add default instructions                            |

### Code Execution Tools

| Function          | Description                                           |
| ----------------- | ----------------------------------------------------- |
| `run_python_code` | Run Python code in the contextual Daytona sandbox     |
| `run_code`        | Run non-Python code in the contextual Daytona sandbox |

You can use `include_tools` or `exclude_tools` to modify the list of tools the agent has access to. Learn more about [selecting tools](/concepts/tools/selecting-tools).

## Developer Resources

- View [Tools](https://github.com/agno-agi/agno/blob/main/libs/agno/agno/tools/daytona.py)
- View [Cookbook](https://github.com/agno-agi/agno/tree/main/cookbook/tools/daytona_tools.py)
- View [Daytona Documentation](https://www.daytona.io/docs/)
